<?php

use Illuminate\Database\Seeder;
use App\Handlers\GetImagesUrlHandler;
class UsersTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker = app(Faker\Generator::class);
        $nums = 1000;
        // 生成1000000用户
        for($i=0; $i<=1000; $i++) {
            $users = factory(App\Models\User::class)->times($nums)->make();
            // 一次性获取头像 url
            $avatars = app(GetImagesUrlHandler::class)->get($nums);
            $avatars = json_decode($avatars, TRUE);

            $users_array = $users->makeVisible(['password', 'remember_token'])->toArray();

            foreach($users_array as $k => $v) {
                $users_array[$k]['avatar'] = $avatars[$k];
            }
            App\Models\User::insert($users_array);
            print("第 $i 批数据插入完成 \n");
        }
    }
}
